package com.unionpay.upmp.sdk.conf;

import java.io.InputStream;
import java.util.PropertyResourceBundle;

import org.apache.log4j.Logger;

  
/**
 * 银联手机支付的配置文件
 *
 */
public class UpmpConfig {

	static final Logger logger = Logger.getLogger(UpmpConfig.class);

	// 版本号
	public static String VERSION;

	// 编码方式
	public static String CHARSET;
	
	// 交易网址
	public static String PHONE_TRADE_URL;
	
	// 查询网址
	public static String PHONE_QUERY_URL;

	// 商户代码
	public static String PHONE_MER_ID;

	// 通知URL
	public static String PHONE_MER_BACK_END_URL;
	
	// 前台通知URL
	public static String PHONE_MER_FRONT_END_URL;
	
	// 返回URL
	public static String PHONE_MER_FRONT_RETURN_URL;
	
	// 加密方式
	public static String SIGN_TYPE;

	// 商城密匙，需要和银联商户网站上配置的一样
	public static String PHONE_SECURITY_KEY;
	
	private static final String KEY_VERSION = "version";
	private static final String KEY_CHARSET = "charset";
	
	private static final String PHONE_KEY_TRADE_URL = "phone.upmp.trade.url";
	private static final String KEY_QUERY_URL = "phone.upmp.query.url";
	private static final String KEY_MER_ID = "phone.mer.id";
	private static final String KEY_MER_BACK_END_URL = "phone.mer.back.end.url";
	private static final String KEY_MER_FRONT_END_URL = "phone.mer.front.end.url";
	private static final String KEY_SIGN_METHOD = "sign.method";
	private static final String KEY_SECURITY_KEY = "phone.security.key";
	
	// 成功应答码
	public static final String RESPONSE_CODE_SUCCESS = "00";

	// 签名
	public final static String SIGNATURE = "signature";
	
	// 签名方法
	public final static String SIGN_METHOD = "signMethod";
	
	// 应答码
	public final static String RESPONSE_CODE = "respCode";
	
	// 应答信息
	public final static String RESPONSE_MSG = "respMsg";
	
	private static final String CONF_FILE_NAME = "upmp.properties";
	
	static {
		
        try {
			InputStream fis = UpmpConfig.class.getClassLoader().getResourceAsStream(CONF_FILE_NAME);
			PropertyResourceBundle props = new PropertyResourceBundle(fis);
			VERSION = props.getString(KEY_VERSION);
			CHARSET = props.getString(KEY_CHARSET);
			PHONE_TRADE_URL = props.getString(PHONE_KEY_TRADE_URL);
			PHONE_QUERY_URL = props.getString(KEY_QUERY_URL);
			PHONE_MER_ID = props.getString(KEY_MER_ID);
			PHONE_MER_BACK_END_URL = props.getString(KEY_MER_BACK_END_URL);
			PHONE_MER_FRONT_END_URL = props.getString(KEY_MER_FRONT_END_URL);
			SIGN_TYPE = props.getString(KEY_SIGN_METHOD);
			PHONE_SECURITY_KEY = props.getString(KEY_SECURITY_KEY);
        } catch(Exception e) {
        	logger.error(e.getMessage(), e);
        }
    }

}
